//
//  PassportViewController.m
//  WisdomCommunity
//
//  Created by Yahaong on 16/7/26.
//  Copyright © 2016年 zonten. All rights reserved.
//  访客通行

#import "PassportViewController.h"
#import "VisitorView.h"
#import "GenerateTXZViewController.h"
#import "YHMarcros.h"
#import "UIView+Frame.h"
@interface PassportViewController ()
/** 业主名称 */
@property(nonatomic, strong)UILabel *nameLabel;
/** 业主名称输入框 */
@property(nonatomic, strong)UITextField *nameTextField;
/** 联系电话 */
@property(nonatomic, strong)UILabel *telLabel;
/** 联系电话输入框 */
@property(nonatomic, strong)UITextField *telTextField;
/** 小区名称 */
@property(nonatomic, strong)UILabel *courtLabel;
/** 小区名称输入框 */
@property(nonatomic, strong)UITextField *courtTextField;
/** 彩带 */
@property(nonatomic, strong)UIImageView *colouredRibbon;

/**底部背景视图 */
@property(nonatomic, strong)UIView *bottomView;

/**访客视图 */
@property(nonatomic, strong)VisitorView *visitorView;

/**生成通行证 */
@property(nonatomic, strong)UIButton *licenceButton;


@end

@implementation PassportViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}

- (void)setupUI
{
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.view.backgroundColor = [UIColor whiteColor];
    [self setupNavigationView];
    [self layoutSubView];

}
- (void)layoutSubView
{
    [self.view addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view);
        make.leading.equalTo(self.view).offset(10);
        make.height.equalTo(45);
    }];
    [self.view addSubview:self.nameTextField];
    [self.nameTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view);
        make.leading.equalTo(self.nameLabel.trailing).offset(20);
        make.height.equalTo(self.nameLabel);
    }];
    
    UIView *nameSplitView = [[UIView alloc]init];
    nameSplitView.backgroundColor = kSplitLineColor;
    [self.view addSubview:nameSplitView];
    [nameSplitView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.bottom);
        make.leading.trailing.equalTo(self.view);
        make.height.equalTo(1);
    }];
    [self.view addSubview:self.telLabel];
    [self.telLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(nameSplitView.bottom);
        make.leading.equalTo(self.nameLabel.leading);
        make.height.equalTo(self.nameLabel.height);
    }];
    [self.view addSubview:self.telTextField];
    [self.telTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.telLabel);
        make.leading.equalTo(self.nameTextField);
        make.height.equalTo(self.telLabel);
    }];
    
    UIView *telSplitView = [[UIView alloc]init];
    telSplitView.backgroundColor = kSplitLineColor;
    [self.view addSubview:telSplitView];
    [telSplitView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.telLabel.bottom);
        make.leading.trailing.equalTo(self.view);
        make.height.equalTo(1);
    }];
    [self.view addSubview:self.courtLabel];
    [self.courtLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(telSplitView.bottom);
        make.leading.equalTo(self.telLabel.leading);
        make.height.equalTo(self.telLabel.height);
    }];
    [self.view addSubview:self.courtTextField];
    [self.courtTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.courtLabel);
        make.leading.equalTo(self.nameTextField);
        make.height.equalTo(self.telLabel);
    }];
    [self.view addSubview:self.colouredRibbon];
    [self.colouredRibbon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.courtLabel.bottom);
        make.leading.trailing.equalTo(self.view);
        make.height.equalTo(15);
    }];
    [self.view addSubview:self.bottomView];
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.equalTo(self.view);
        make.top.equalTo(self.colouredRibbon.bottom);
    }];
    [self.bottomView addSubview:self.visitorView];
    [self.visitorView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.equalTo(self.bottomView).offset(10);
        make.trailing.equalTo(self.bottomView).offset(-10);

        make.height.equalTo(kIphoneSize_Height(200));
    }];
    [self.bottomView addSubview:self.licenceButton];
    [self.licenceButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.visitorView.bottom).offset(kIphoneSize_Height(100));
        make.left.equalTo(self.bottomView).offset(10);
        make.trailing.equalTo(self.bottomView).offset(-10);
        make.height.equalTo(kIphoneSize_Height(50));
    }];
    
    
}
- (void)setupNavigationView
{
    self.navigationItem.title = @"访客通行证";
    UIButton *button = [[UIButton alloc]init];
    [button addTarget:self action:@selector(historyClick) forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:@"历史" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button sizeToFit];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
}
-(void)historyClick
{
   debugLogInfo(@"historyClick");
}

- (void)licenceButtonClick
{
    GenerateTXZViewController * txzVc  = [[GenerateTXZViewController alloc]init];
    [self.navigationController pushViewController:txzVc animated:YES];
}
#pragma mark -  lazy loading
- (UILabel *)nameLabel
{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.text = @"业主名称";
       
    }
    return _nameLabel;
}

- (void)cancel
{
    
}

- (void)compose
{
    [UIView animateWithDuration:0.25 animations:^{
            [self.view endEditing:YES];
    }];

}
- (UITextField *)nameTextField
{
    if (!_nameTextField) {
        _nameTextField = [[UITextField alloc]init];
        _nameTextField.placeholder = @"请填写你的真实姓名";
        UIToolbar *toolBar = [[UIToolbar alloc]init];
        toolBar.yh_height = 40;
        UIBarButtonItem *cancel = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStyleDone target:self action:@selector(cancel)];
        
        UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
        
        UIBarButtonItem *compose = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(compose)];
        toolBar.items = @[cancel, flexibleSpace,compose];
        _nameTextField.inputAccessoryView = toolBar;
    
        
       
    }
    return _nameTextField;
}
- (UILabel *)telLabel
{
    if (!_telLabel) {
        _telLabel = [[UILabel alloc]init];
        _telLabel.text = @"联系电话";

    }
    return _telLabel;
}

- (UITextField *)telTextField
{
    if (!_telTextField) {
        _telTextField = [[UITextField alloc]init];
        _telTextField.placeholder = @"请填写你的电话号码";

    }
    return _telTextField;
}
- (UILabel *)courtLabel
{
    if (!_courtLabel) {
        _courtLabel = [[UILabel alloc]init];
        _courtLabel.text = @"小区名字";
    }
    return _courtLabel;
}

- (UITextField *)courtTextField
{
    if (!_courtTextField) {
        _courtTextField = [[UITextField alloc]init];
        _courtTextField.placeholder = @"蔚蓝卡地亚2栋1单元0201室";
    }
    return _courtTextField;
}
- (UIImageView *)colouredRibbon
{
    if (!_colouredRibbon) {
        _colouredRibbon = [[UIImageView alloc]init];
        _colouredRibbon.image = [UIImage imageNamed:@"passport_icon_background"];
    }
    return _colouredRibbon;
}
- (UIView *)bottomView
{
    if (!_bottomView) {
        _bottomView = [[UIView alloc]init];
        _bottomView.backgroundColor = kBgColor;
    }
    return _bottomView;
}

- (VisitorView *)visitorView
{
    if (!_visitorView) {
        _visitorView = [[VisitorView alloc]init];
        
    }
    return _visitorView;
}

- (UIButton *)licenceButton
{
    if (!_licenceButton) {
        _licenceButton = [[UIButton alloc]init];
        [_licenceButton setTitle:@"生成访客通行证" forState:UIControlStateNormal];
        _licenceButton.layer.cornerRadius = 10;
        _licenceButton.layer.masksToBounds = YES;
        _licenceButton.backgroundColor = kGlobalRedColor;
        [_licenceButton addTarget:self action:@selector(licenceButtonClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _licenceButton;
}
@end
